package cn.edu.jxau.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.jxau.domain.reply;
import cn.edu.jxau.domain.userInfo;
import cn.edu.jxau.service.userInfoService;

/**
 * 这是一个对用户信息管理的控制层组件
 * 
 * @author 刘勋承
 *
 */
public class userInfoServlet extends HttpServlet {
	private userInfoService userInfoService = new userInfoService();

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String username = (String) request.getSession().getAttribute("username");

		if (username != null && request.getSession().getAttribute("flag").equals("ok")) {
			userInfo userInfo = userInfoService.findUserInfoByUsername(username);// 得到用户相关信息
			request.getSession().setAttribute("userInfo", userInfo);
			String mail = userInfoService.findMailByUsername(username);// 得到邮箱
			request.getSession().setAttribute("mail", mail);
			int total = userInfoService.findTotal(username);// 得到指定用户的发帖数
			request.getSession().setAttribute("usertotal", total);
			
			List<Map<String, Object>> myReply=userInfoService.findMyReply(username);
			request.getSession().setAttribute("myReply", myReply);//得到的是一个key-title key-reply_content的map的list集合
			
			List<Map<String,Object>> replyMy=userInfoService.findReplyMy(username);
			request.getSession().setAttribute("replyMy", replyMy);
			
		}

		response.sendRedirect("info.jsp");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String username = (String) request.getSession().getAttribute("username");

		userInfo userInfo = userInfoService.findUserInfoByUsername(username);// 得到用户相关信息
		request.getSession().setAttribute("userInfo", userInfo);
		String mail = userInfoService.findMailByUsername(username);// 得到邮箱
		request.getSession().setAttribute("mail", mail);
		int total = userInfoService.findTotal(username);// 得到指定用户的发帖数
		request.getSession().setAttribute("usertotal", total);

		response.sendRedirect("info.jsp");
	}
}
